package com.fujimana.rockincat.restree.service;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

public class Response {
	
	private int status;
	
	private Map<String, String> headerMap;
	
	private String redirectUri;
	
	private String charset;
	
	private String contentType;
	
	private Locale locale;
	
	public Locale getLocale() {
		return locale;
	}

	public void setLocale(Locale locale) {
		this.locale = locale;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public String getCharset() {
		return charset;
	}

	public void setCharset(String charset) {
		this.charset = charset;
	}

	Response() {
		headerMap = new HashMap<String, String>();
		status = 200;
		redirectUri = null;
	}

	public Set<String> getHeaderKeys() {
		return headerMap.keySet();
	}

	void setHeaderMap(Map<String, String> headerMap) {
		this.headerMap = headerMap;
	}

	public String getHeader(String key) {
		return headerMap.get(key);
	}

	public void setHeader(String key, String value) {
		headerMap.put(key, value);
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public boolean isRedirect() {
		return redirectUri != null;
	}
	
	public void redirect(String uri) {
		this.redirectUri = uri;
	}
	
	String getRedirectUri() {
		return redirectUri;
	}
	
	private static ThreadLocal<Response> response = new ThreadLocal<Response>() {

		@Override
		protected Response initialValue() {
			return null;
		}

	};
	
	static void setResponse(Response res) {
		response.set(res);
	}

	public static Response getResponse() {
		return response.get();
	}
}
